<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <meta charset="UTF-8">
  <meta name="author" content="wangbo">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    // 判断数组是不是有序  
    //要么从小到大,要么从大到小
    let arr = [5, 4, 3, 6, 22, 77, 10, 2]
    // let arr = [1,22,33,44,55]
    // let arr = [22,12,10,8,5]    

    let isSort = function (arr) {
      let isheng = isjiang = 0
      for (let i = 0; i < arr.length - 1; i++) {
        if (arr[i] < arr[i + 1]) {
          isheng++;
        }
        if (arr[i] > arr[i + 1]) {
          isjiang++;
        }
      }
      if (isheng == arr.length - 1) {
        console.log("升序");
      } else if (isjiang == arr.length - 1) {
        console.log("降序");
      } else {
        ;
        console.log("乱序");
      }
    }
    isSort(arr)


    let issheng = arr.every((item, i) => {
      if (i != arr.length - 1) {
        return item < arr[i + 1]
      } else {
        return true
      }
    })
    let isjiang = arr.every((item, i) => {
      if (i != arr.length - 1) {
        return item > arr[i + 1]
      } else {
        return true
      }
    })
    console.log(issheng, isjiang);




    let isSort = function (arr) {
      let isheng = isjiang = false;
      for (let i = 0; i < arr.length - 1; i++) {
        if (arr[i] < arr[i + 1]) {
          isheng = true;
        }
        if (arr[i] > arr[i + 1]) {
          isjiang = true;
        }
        if (isheng && isjiang) {
          break;
        }
      }
    }
    isSort(arr)






  </script>
</body>

</html>